/**
 * 
 */
package com.kovell.profileo.utils;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.kovell.profileo.exception.ServiceException;

/**
 * @author SOSSERES
 *
 */
public class ServiceLocator {

	/**
	 * @throws ServiceException 
	 * 
	 */

//	public static <T> T lookup(Class<T> clazz) throws NamingException{
//		Context ctx = new InitialContext();
//		String jndi = clazz.getSimpleName() + "Bean#" + clazz.getName();
//		System.out.println("Lookup " + clazz.getSimpleName());
//		return (T) ctx.lookup(jndi);
//	}
	
	
	public static <T> T lookup(Class<T> clazz) throws ServiceException {
		
		try {
			Context ctx = new InitialContext();

			String jndi = clazz.getSimpleName() + "Bean#" + clazz.getName();
			System.out.println("Lookup " + clazz.getSimpleName());
			return (T) ctx.lookup(jndi);
			
		} catch (NamingException e) {
			e.printStackTrace();			
			throw new ServiceException("PFO-002");
		}
	}
}
